package com.guli.auth.config;

import lombok.Data;
import lombok.Setter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/*
 * @Author 罗
 * @date 2020/10/19 - 12:44 下午
 */
@Component
@ConfigurationProperties(prefix = "weibo")
@Data
public class WeiBoSecretProperties implements InitializingBean {

    // 使用格式化字符串教程 https://blog.csdn.net/lonely_fireworks/article/details/7962171/
    private static final String  URL_FOR_GET_ACCESS_TOKEN_UNFORMATTED = "https://api.weibo.com/oauth2/access_token?client_id=%s&client_secret=%s&grant_type=authorization_code&redirect_uri=%s&code=";

    // 新浪 根据用户ID获取用户信息 ，api 文档 https://open.weibo.com/wiki/2/users/show
    private static final String URL_FOR_SHOW_USER_INFO = "https://api.weibo.com/2/users/show.json";

    // 授权类型
    public static final String GRANT_TYPE = "authorization_code";


    public static String UrlForGetAccessToken;

    private String clientId;

    private String clientSecret;

    private String redirectUri;

    @Override
    public void afterPropertiesSet() throws Exception {
        UrlForGetAccessToken = String.format(URL_FOR_GET_ACCESS_TOKEN_UNFORMATTED,clientId,clientSecret,redirectUri);
    }
}
